package org.example.web;

import org.example.model.Event;
import org.example.model.Result;
import org.example.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController //功能是将类声明为一个控制器，并使其中的方法可以直接响应HTTP请求
@RequestMapping("/userApi/eventCtl")
public class EventController {
    @Autowired
    private EventService eventService;

    @RequestMapping(path = "/info", method = RequestMethod.GET )
    public Result getEvents() {
        List<Event> events = eventService.getEvents();
        return new Result(200, "success", events);
    }
    @RequestMapping(path = "/findById", method = RequestMethod.GET )
    public Result getEventById(@RequestParam("id") int id) {
        Event event = eventService.getEventById(id);
        return new Result(200, "success", event);
    }


}
